package com.dg11185.nearshop.net.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.dg11185.nearshop.net.entity.Activity;

/**
 * 
 * @author：Daibo    
 * @time：2014-8-22 下午3:20:43
 */
public class GetActivityListResponse {

    public NetStatus status = NetStatus.NULL_STATUS;
    
    public int total ;
    
    public List<Activity> activities = null;
    
    public GetActivityListResponse(){
        activities = new ArrayList<Activity>();
    }
    
    public void parseJson(String response){

        try {
            JSONObject jsonObject = new JSONObject(response);
            total = Integer.parseInt(jsonObject.optString("total", "0"));
            
            status = NetStatus.getStatus(jsonObject.optString("status"));
            
            if(!jsonObject.isNull("activityList")){
                JSONArray array = jsonObject.optJSONArray("activityList");
                
                for(int a=0; a<array.length(); a++){
                    Activity record = new Activity();
                    record.parseEntity(array.getJSONObject(a));
                    activities.add(record);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
}
